<template>
	<view class="article-main">
		<view class="header">
			<view class="imgs">
				<image class="img" :src="article.coverImg" mode=""></image>
			</view>
			<view class="collect" @tap="collect">
				<image class="image" src="../../../static/icons/xin.png" mode="scaleToFill"></image>
			</view>
		</view>
		<view class="content">
			<view class="title">
				<view class="title1">{{article.title}}</view>
				<view class="title2">{{article.author}}</view>
			</view>
			<view class="col">
				<view class="cols">
					<view class="dotts">
						<span class="dott" :style="{backgroundColor:item}" v-for="item in color" :key="item.id"></span>
					</view>
					<view class="col2">
						￥{{article.price}}
					</view>
				</view>
			</view>
		</view>
		<view class="rich">
			<rich-text :nodes="article.content1"></rich-text>
		</view>
		<view class="img1">
			<image class="imgs" :src="article.coverImg" mode=""></image>
		</view>
		<view class="footer">
			<div class="footers">
				<div class="f1">
					{{article.viewCount}}<image class="img" src="../../../static/icons/chat.png" mode=""></image>
				</div>
				<div class="f2">
					{{article.zanCount}}<image class="img" src="../../../static/icons/zan.png" mode=""></image>
				</div>
			</div>
		</view>
	</view>
</template>

<script>
	import findApi from '@/api/find/index.js'
	export default {
		name: 'Article',
		data() {
			return {
				id: '',
				article: {},
				color:[]
			}
		},
		onLoad(option) {
			this.id = option.articleId;
			this.getArticleDetail();
		},
		methods: {
			async getArticleDetail() {
				var {
					data
				} = await findApi.articleDetail({
					id: this.id
				});
				this.article = data;
				for(var item in data){
					//indexOf方法返回一个整数值,指出String对象内子字符串的开始位置.如果没有找到子字符串,返回-1
					if(item.indexOf('color')!=-1){
						this.color.push(data[item]);
					}
				}
				console.log(this.color);
			},
			collect() {
				uni.showToast({
					title: '已添加到心愿单!',
					duration: 800
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.article-main {
		height: 100%;
		.header {
			width: 100%;
			// height: 700rpx;
			.imgs{
				height: 546rpx;
				width: 100%;
				.img {
					width: 100%;
					height: 100%;
					border-radius: 0px 0px 0px 80px;
				}
			}
			.collect{
				position: absolute;
				width: 100rpx;
				height: 100rpx;
				top: 515rpx;
				right: 100rpx;
				margin-top: -20rpx;
				background: #354E44;
				box-shadow: 0 16px 24px 0 rgba(70, 70, 70, 0.20);
				text-align: center;
				border-radius: 50%;
				.image{
					width: 44rpx;
					height: 44rpx;
					margin-top: 29rpx;
				}
			}
		}
		.content{
			width: 100%;
			height: 150rpx;
			margin-top: 48rpx;
			.title{
				height: 120rpx;
				width: 600rpx;
				margin-left: 80rpx;
				.title1{
					width: 400rpx;
					font-size: 40rpx;
					color: #3E3E3E;
					letter-spacing: 1.3px;
					font-family: PingFangSC-Semibold;
				}
				.title2{
					width: 200rpx;
					font-size: 15.4px;
					color: #B0B0B0;
					letter-spacing: 1.1px;
					font-family: PingFangSC-Regular;
				}
			}
			.col{
				width: 100%;
				height: 35rpx;
				display: flex;
				justify-content: space-around;
				padding-top: 25rpx;
				.cols{
					width: 600rpx;
					margin: 0 auto;
					display: flex;
					justify-content: space-between;
					align-items: center;
					.dotts{
						width: 100%;
						margin-top: 20rpx;
						.dott {
							float: left;
							width: 20rpx;
							height: 20rpx;
							margin: 0 10rpx;
							border-radius: 50%;
						}
					}
					.col2{
						font-size: 40rpx;
						color: #3E3E3E;
						letter-spacing: 1.3px;
					}
				}
			}
		}
		.rich{
			margin-top: 100rpx;
			width: 622rpx;
			margin-left: 80rpx;
			rich-text{
				margin: 10rpx 40rpx;
				font-size: 28rpx;
				color: #8A8A8A;
				letter-spacing: 1px;
			}
		}
		.img1{
			width: 100%;
			.imgs{
				height: 400rpx;
				width: 100%;
			}
		}
		.footer{
			width: 100%;
			height: 70rpx;
			margin-top: 38rpx;
			.footers{
				float: right;
				width: 450rpx;
				height: 100%;
				display: flex;
				justify-content: space-around;
			}
			.f1{
				width: 180rpx;
				height: 45rpx;
				font-size: 28rpx;
				color: #3E3E3E;
				letter-spacing: 1px;
				.img{
					margin-left: 24rpx;
					width: 40rpx;
					height: 40rpx;
				}
			}
			.f2{
				font-size: 28rpx;
				color: #3E3E3E;
				letter-spacing: 1px;
				margin-left: 40rpx;
				width: 180rpx;
				height: 45rpx;
				.img{
					margin-left: 24rpx;
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
	}
</style>
